package cc.momas;

import com.alibaba.excel.EasyExcel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

/**
 * @author Sod-Momas
 * @since 2021-04-16
 */
public class HeishimiExportTxt {
    private static final Logger log = LoggerFactory.getLogger(HeishimiExportTxt.class);

    public static void main(String[] args) {
        System.out.println("正在准备输出txt");
//        checkJdkVersion();
        readExcel();
        System.out.println("输入完成，现在自动打开输出目录");
        openDir();
    }

    private static void openDir() {
        try {
            Runtime.getRuntime().exec("explorer " + ExportListener.outputPath.toAbsolutePath());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    private static void readExcel() {
        final ExportListener listener = new ExportListener();
        EasyExcel.read("a.xlsx")
//        EasyExcel.read("C:\\Users\\sod\\Downloads\\a.xlsx")
                .registerReadListener(listener)
                .sheet()
                .doRead();
    }

    private static void checkJdkVersion() {
        String jdkVersion = System.getProperty("java.version");
        // 由于cglib不再支持新版本jdk，所以只能要求jdk8
        if (!jdkVersion.contains("1.8")) {
            throw new RuntimeException("easyexcel要求jdk 1.8,当前jdk版本为：" + jdkVersion);
        }
    }
}
